from emmodels.em_basemodel import BaseModel




class BaseTradeHis(BaseModel):

    BaseModel.loadTable('EM_BASETRADEHIS')

    def __init__(self, tradeDay, tradeTime, stkCode, stkName, tradeType, tradePrice, tradeCount, tradeTotalMoney, operationDetail, tradeSource):
        self.hisid = None
        self.trade_day = tradeDay
        self.trade_time = tradeTime
        self.stk_code = stkCode
        self.stk_name = stkName
        self.trade_type = tradeType
        self.trade_price = tradePrice
        self.trade_count = abs(tradeCount)
        self.total_money = tradeTotalMoney
        self.operationDetail = operationDetail
        self.trade_source = tradeSource


class ZXTradeHis(BaseTradeHis):
    def __init__(self, zxRecord):
        if isinstance(zxRecord, list):
            # ['20151102', '18:56:56', '15', '660001', '报价标准券', '卖出', 1.6, -370.0, 37001.62, 37001.62, '15', '20151030',
            #  '拆出报价购回', '0186265187', '880000910112', '880000919039', '郑建宝', '深圳A股', '深圳报价回购(购回交易)-132002']
            super().__init__(zxRecord[0], zxRecord[1], zxRecord[3], zxRecord[4], zxRecord[12], zxRecord[6], zxRecord[7],
                             zxRecord[8],zxRecord[12],'ZX')

    def isCorrect(self):
        if (self.operationDetail == '证券买入' or self.operationDetail == '证券卖出') and self.stk_name != '报价标准券':
            return True
        return False


class YHTradeHis(BaseTradeHis):
    operationDeteal = ''

    def __init__(self, yhRecord):
        if isinstance(yhRecord, list):
            # 购买日期 成交时间 证券代码 证券名称 买卖标志 成交价格 成交数量 成交金额 协议编号 股东代码 交易市场
            # 20141013 11:18:39 000050 深天马Ａ 证券买入 24.1 1000 24100 DL002428 0150572662 深圳A股
            super().__init__(yhRecord[0], yhRecord[1], yhRecord[2], yhRecord[3], yhRecord[4], yhRecord[5], yhRecord[6],
                             yhRecord[7],yhRecord[4],'YH')

    def isCorrect(self):
        if (self.operationDetail == '证券买入' or self.operationDetail == '证券卖出'):
            return True
        return False
